import install from "./install"
import createMatcher from "./creat-matcher"
import HashHistory from "./history/hash"
import Html5History from "./history/html5"
export default class VueRouter {
  constructor(options) {
    this._routes = options.routes || []
    this.matcher = createMatcher(this._routes)
    const mode = this.model = options.mode || 'hash'
    switch (mode) {
      case 'hash':
        this.history = new HashHistory(this)
        break;
      case 'histroy':
        this.history = new Html5History(this)
        break;
      default:
        throw new Error('mode error')
    }
  }
  //注册路由变化事件，参数是vue实例
  // init(Vue) {}s
  init(Vue) {
    const history = this.history
    const setUpListener = () => {
      history.setUpListener()
    }
    history.transitionTo(history.getCurrentLocation(),setUpListener)
    history.listen((route)=>{
      Vue._route = route
    })
  }
}
VueRouter.install = install